<?php
namespace App\Http\Controllers\Api\Trade\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Api\Controller;
use App\Models\Trade\Common\FishKindUnitSizeModel;
use App\Models\Trade\Common\FishKindUnitPriceModel;
use App\Models\Trade\Common\FishKindRegularSizeModel;
use App\Models\Trade\Sub\DescTagModel;
use App\Models\Trade\Sub\ValidityModel;
use App\Services\Utils\TencentYun\ImageService;
use TencentYun\Image\ImageV2;

class CommonController extends Controller
{
    
    public function getMyInfo()
    {
        return $this->response->setResponseData($this->identity())->getResponse();
    }

    /**
     * 获取品种辅助信息
     *
     * @param $kind_id 必选            
     */
    public function getFishKindSub(Request $request)
    {
        $this->validate($request, [
            'kind_id' => 'required|integer|min:1'
        ]);
        $kindId = $request->query('kind_id');
        
        $data['unit_size'] = FishKindUnitSizeModel::selectByKindId($kindId)->all();
        $data['unit_price'] = FishKindUnitPriceModel::selectByKindId($kindId)->all();
        $data['regular_size'] = FishKindRegularSizeModel::selectByKindId($kindId)->all();
        
        return $this->response->setResponseData($data)->getResponse();
    }

    /**
     * 获取描述标签列表
     */
    public function getDescTagList()
    {
        $data = DescTagModel::selectAll()->pluck('name')->all();
        
        return $this->response->setResponseData($data)->getResponse();
    }

    /**
     * 获取有效时间列表
     */
    public function getValidityList()
    {
        $collection = ValidityModel::selectAll();
        $data = ValidityModel::makeDataListDecode($collection);
        
        return $this->response->setResponseData($data)->getResponse();
    }

    /**
     * 获取上传图片相关参数
     */
    public function getTencentAuth()
    {
        // 使用腾讯SDK生成上传图片路径URI
        $data['uri'] = ImageV2::generateResUrl(ImageService::BUCKET_TRADE, 0);
        // 制作腾讯云签名
        $data['auth'] = ImageService::makeTencentSign(ImageService::BUCKET_TRADE);
        
        return $this->response->setResponseData($data)->getResponse();
    }
}
